import { Button } from '@nutui/nutui-react';
import { parse } from 'querystring';
import { useEffect } from 'react';
export default function Test() {
  // const login = () => {
  //   let pas = {
  //     redirectUrl: window.location.href,
  //     isLogin: '1'
  //   };
  //   pas = encodeURIComponent(JSON.stringify(pas)) as any;
  //   const url = `szbsales://web/redirect?appId=20210022&url=/pages/thirdTranSit/thirdTranSit&params=${pas}`;
  //   console.log(url);
  //   window.location.href = url;
  // };
  const getCode = () => {
    const res = window.location.search.replace('?', '');
    const { code = '' } = parse(res);
    // 已经授权登录过的就不用再授权了
    // 如果拿到code，调用授权接口，没有拿到就跳转微信授权链接获取
    if (code) {
      console.log('shouquan');
    } else {
      const wxUrl =
        'https://open.weixin.qq.com/connect/qrconnect?appid=wx432b639258e4cdb6&redirect_uri=http://bonus.okaok.com.cn/test&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect';
      console.log('window.location.href---', wxUrl);
      window.location.href = wxUrl; // 这个时候页面一定会刷新,进入到给的redirect_uri中
    }
  };
  useEffect(() => {
    getCode();
  }, []);
  const login = () => {
    console.log('11');
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    // 获取code
  };
  return (
    <div>
      <Button onClick={login}>登录</Button>
      <div id="login_container"></div>
    </div>
  );
}
